package com.alex.xmlyfm.tasks;

/**
 * Created by
 * Author: alex
 * Email:
 * Date: 15-10-20.
 */

import android.util.Log;

import com.alex.mylibrary.tasks.BaseTask;
import com.alex.mylibrary.tasks.TaskCallBack;
import com.alex.mylibrary.tasks.TaskResult;
import com.alex.xmlyfm.Constants;
import com.alex.xmlyfm.client.ClientAPI;
import com.alex.xmlyfm.entities.EntityParseUtil;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 发现部分 分类 的数据加载异步任务
 */
public class DiscoverCategoryTask extends BaseTask {

    public DiscoverCategoryTask(TaskCallBack callBack) {
        super(callBack);
    }


    @Override
    protected TaskResult doInBackground(String... params) {
        TaskResult ret = new TaskResult();
        // 唯一的标识
        ret.action = Constants.TASK_ACTION_CATEGORIES;
        JSONObject jsonObject = ClientAPI.getDiscoverCategories();

        if (jsonObject != null) {
            try {
                ret.resultCode = jsonObject.getInt("ret");

                ret.data = EntityParseUtil.parseDiscoverCategories(jsonObject);
                Log.d("taskcategory", ret.data.toString());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        return ret;
    }

}
